package com.xbongbong.paas.service.workflow.approveListPage.impl;

import com.xbongbong.paas.enums.ProcessSearchStatusAllEnum;
import com.xbongbong.paas.enums.ProcessSearchStatusCcEnum;
import com.xbongbong.paas.enums.ProcessSearchStatusCreateEnum;
import com.xbongbong.paas.enums.ProcessSearchStatusTodoEnum;
import com.xbongbong.paas.enums.ProcessTypeEnum;
import com.xbongbong.paas.enums.clazz.ProcessTypeClass;
import com.xbongbong.paas.pojo.dto.ProcessTypeListDTO;
import com.xbongbong.paas.pojo.vo.ProcessTypeListVO;
import com.xbongbong.paas.service.workflow.approveListPage.WorkflowListSearchService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author 魏荣杰
 *
 */
@Slf4j
@Service("workflowListSearchService")
public class WorkflowListSearchServiceImpl implements WorkflowListSearchService {


    @Override
    public ProcessTypeListVO getProcessTypeList(ProcessTypeListDTO processTypeListDTO) throws XbbException {
        ProcessTypeListVO processTypeListVO = new ProcessTypeListVO();
        List<ProcessTypeClass> processTypeList;
        try {
            String processType = processTypeListDTO.getProcessType();
            if (processType.equals(ProcessTypeEnum.TODO.getValue())) {
                processTypeList = new ArrayList<>();
            } else if (processType.equals(ProcessTypeEnum.CREATE.getValue())) {
                processTypeList = ProcessSearchStatusCreateEnum.getProcessTypeList();
            } else if (processType.equals(ProcessTypeEnum.CC.getValue())) {
                processTypeList = ProcessSearchStatusCcEnum.getProcessTypeList();
            } else if (processType.equals(ProcessTypeEnum.ALL.getValue())) {
                processTypeList = ProcessSearchStatusAllEnum.getProcessTypeList();
            } else if (processType.equals(ProcessTypeEnum.HAVE_DONE.getValue())){
                processTypeList = ProcessSearchStatusTodoEnum.getProcessTypeList();
                processTypeList.remove(0);
            } else {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100028, SystemErrorCodeEnum.API_ERROR_100028.getMsg());
            }
            processTypeListVO.setProcessTypeList(processTypeList);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            log.error("获取工作流流程状态筛选项出错，platfrom：" + processTypeListDTO.getPlatform(), e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return processTypeListVO;
    }
}
